package com.chonglie.listview;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ListViewAdapter extends BaseAdapter {

	private List<Item> items;
	private List<View> views;

	public ListViewAdapter(List<Item> items, ItemViewHandler handler) {
		this.items = items;
		this.views = new ArrayList<View>(items.size());

		for (Item item : items) {
			views.add(handler.makeItemView(item));
		}

	}

	public int getCount() {
		return items.size();
	}

	public Object getItem(int position) {
		return views.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			return views.get(position);
		} else {
			return convertView;
		}
	}
}
